//工具生成，请不要手动修改...
let ObjEncoder: any, ObjDecoder: any
/** 需要传入kcoder模块来进行初始化 */
export function initProto(kcoder: { ObjEncoder: any, ObjDecoder: any }) {
    ObjEncoder = kcoder.ObjEncoder
    ObjDecoder = kcoder.ObjDecoder
}

/** 协议 */
export const enum Proto {
    /** 测试协议 */
    test = 1,
}

const ST = {
    com_test: () => [["x", 5], ["y", 5]],
    test_test: () => [["a", 5], ["b", 5]],
}

const STRUCT_TOS: any = {
    1: [["a", 5], ["b", 5], ["c", 5], ["com", 16, ST.com_test()]],
}

const STRUCT_TOC: any = {
    1: [["a", 5], ["b", 5], ["c", 5], ["test", 16, ST.test_test()]],
}

/** 协议Vo定义 */
export namespace ProtoVo {

    /** 协议请求结构定义 */
    export type TosDef = {
        [Proto.test]: vo_tos_test
    }

    /** 协议返回结构定义 */
    export type TocDef = {
        [Proto.test]: vo_toc_test
    }

    /** 二进制数据转换为协议vo(发服务端) */
    export function fromBytesTos(bytes: Uint8Array) {
        let protocol: number, data = ObjDecoder.decodeDeal(bytes, (r: any) => { protocol = r.uint; return STRUCT_TOS[protocol] })
        return { protocol, data }
    }

    /** 协议vo转换为二进制数据(发服务端) */
    export function toBytesTos<P extends keyof TosDef>(protocol: P, data: TosDef[P]) {
        return ObjEncoder.encodeDeal(data, STRUCT_TOS[protocol], (w: any) => w.uint = protocol)
    }

    /** 二进制数据转换为协议vo(发客户端) */
    export function fromBytesToc(bytes: Uint8Array) {
        let protocol: number, data = ObjDecoder.decodeDeal(bytes, (r: any) => { protocol = r.uint; return STRUCT_TOC[protocol] })
        return { protocol, data }
    }

    /** 协议vo转换为二进制数据(发客户端) */
    export function toBytesToc<P extends keyof TocDef>(protocol: P, data: TocDef[P]) {
        return ObjEncoder.encodeDeal(data, STRUCT_TOC[protocol], (w: any) => w.uint = protocol)
    }

    /** 通用结构 */
    export interface vo_com_test {
        /** x */
        x: number
        /** y */
        y: number
    }

    /** 内部结构 */
    export interface vo_test_test {
        a: number
        b: number
    }

    /** 发服务端协议 */
    export interface vo_tos_test {
        a: number
        b: number
        c: number
        /** 使用通用结构 */
        com: vo_com_test
    }

    /** 发客户端协议 */
    export interface vo_toc_test {
        a: number
        b: number
        c: number
        /** 使用内部结构 */
        test: vo_test_test
    }

}